#include <stdio.h>
#include <string.h>

int n, m, r, c;
char tu[110][110];

int ans;

bool init()
{
    if (scanf("%d%d%d%d", &n, &m, &r, &c)==EOF) return false;
    if (n==0 && m==0 && r==0 && c==0) return false;
    int i;
    memset(tu, 0, sizeof(tu));
    for (i=1; i<=n; ++i)
        scanf("%s", &tu[i][1]);        
    return true;
}    

void remove(int i, int j)
{
    int x, y;
    int tox, toy;
    tox = i+r-1;
    toy = j+c-1;
    for (x=i; x<=tox; ++x)
        for (y=j; y<=toy; ++y)
            if (tu[x][y]=='0') tu[x][y] ='1';
            else tu[x][y] = '0';
}    


void deal()
{
    ans = 0;
    int i, j;
    for (i=1; i<=n-r+1; ++i)
    {
        for (j=1; j<=m-c+1; ++j)
             if (tu[i][j] == '1')
             {
                 remove(i, j);
                 ans ++;
             }        
        // check the rest
        for (  ; j<=m; ++j)
            if (tu[i][j] == '1')
            {
                ans = -1; 
                return ;
            }    
    }    
    // check the rest
    for (  ; i<=n; ++i)
        for (j=1; j<=m; ++j)
            if (tu[i][j] == '1')
            {
                ans = -1; 
                return ;
            }    
}    

int main()
{
    while (init())
    {
        deal();
        printf("%d\n", ans);
    }    
    
    return 0;    
}   
 

